// 创建一个学生Reducer
const stuReducer = (state = {
    name: '张三',
    age: 20,
    sex: '男'
    // action参数是动作：action有两个属性，type是类型，payload是更新的最新值
}, action) => {
    // 判断动作类型：就是判断type确定给状态的哪个属性更新最新值
    switch (action.type) {
        case 'setStu':
            return {
                ...action.payload
            }
        case 'setStuName':
            return {
                ...state,
                // 更新指定属性的状态
                name: action.payload
            }
        case 'setStuAge':
            return {
                ...state,
                age: action.payload
            }
        case 'setStuSex':
            return {
                ...state,
                sex: action.payload
            }
        default:
            return state
    }
}

export default stuReducer
